package com.lft07.status;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Function: 		A {@code TestSleep} 模拟倒计时<br/>
 * Reason:   		<br/>
 * <p>
 * Date:            2021-01-27 14:20<br/>
 * <p>
 * Class Name:      TestSleep<br/>
 * Package Name:    com.lft07.status<br/>
 * @author Laifengting / E-mail:laifengting@foxmail.com
 * @version 1.0.0
 * @since JDK 8
 */
public class TestSleep2 {
	public static void tenDown() {
		int num = 10;
		while (true) {
			try {
				Thread.sleep(1000);
				System.out.println(num--);
				if (num <= 0) {
					break;
				}
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			
		}
	}
	
	public static void main(String[] args) {
		// tenDown();
		// 打印当前系统时间，获取系统当前时间
		// Date startTime = new Date(System.currentTimeMillis());
		
		DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		Date startTime = new Date();
		String dateStr = dateFormat.format(startTime);
		System.out.println(dateStr);
		
		while (true) {
			try {
				Thread.sleep(1000);
				System.out.println(new SimpleDateFormat("HH:mm:ss").format(startTime));
				// 更新当前时间
				startTime = new Date(System.currentTimeMillis());
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
		}
		
	}
	
}
